<?php
/**
 * 描述
 * Created by Paco
 * Date: 2018/8/21 Time: 18:14
 */

namespace App\Http\Request\Auth;


use App\Http\Request\Store;

class AdminStore extends Store
{

    private $method;

    public function rules()
    {
        $this->method = strtoupper($this->method());

        $rules = [
            'name' => 'required',
            'roles' => 'required|array',
            'roles.*' => 'required'
        ];
        if ($this->method == 'POST') {
            $rules = [
                'tel' => 'required|regex:/^1[345678]\d{9}$/|unique:admin,tel',
                'password' => 'required|confirmed',
                'name' => 'required',
                //'code' => 'required|integer',
                'roles' => 'required|array',
                'roles.*' => 'required'
            ];
        } elseif ($this->method == 'PUT') {
            $rules = [
                'admin_id' => 'required|integer',
                'password' => 'sometimes|required',
                'name' => 'required',
                'roles' => 'required|array',
                'roles.*' => 'required'
            ];
        }
        return $rules;
    }


    public function after()
    {
//        $params = $this->validateData();
//
//        if ($this->method == 'PUT') {
//            if (isset($params['tel'])) {
//                $this->throwRespondError(10311);
//            }
//        } elseif ($this->method == 'POST') {
//            $code =123456;//app('phpredis')->get('sms_code_' . $params['tel'])??;
//            if (  $code != $params['code']) {
//                $this->throwRespondError(10302);
//            }
//        }

        return true;
    }
}